
function showEditor(){
    document.getElementById("Layer1").style.display = "";
	var top = (document.body.clientHeight-600)/2+"px";
	var left = (document.body.clientWidth-760)/2+"px";
	var div = document.getElementById("Layer1");
	div.style.top = top;
	div.style.left = left;
	showEdit();
}


function showEdit(id){
	 document.getElementById("bgLayer").width = document.body.scrollWidth; 
	 document.all["bgLayer"].style.display="";
	 document.all["bgLayer"].style.height=document.body.scrollHeight;
	 document.getElementById("Layer1").style.display="";
	 timer=setInterval(move,"100");
}
function hideEdit(){
clearInterval(timer);
document.all["bgLayer"].style.display="none";
document.all["Layer1"].style.display="none";
}
function move(){
document.all["Layer1"].style.top=document.body.scrollTop+(document.body.clientHeight-600)/2;
document.all["Layer1"].style.left=document.body.scrollLeft+document.body.clientWidth/2-380;
}


function displayDiv(){
   document.getElementById("Layer1").style.display = "none";
   hideEdit();
}

function submitText(url){
	var title =    document.getElementById("descTitle").value;
	var desc = CKEDITOR.instances.serviceContent.getData();
	if(title!=""&&desc!=""){
		$.post(url,
			       { descriptionName: title, descriptionValue: desc,addServiceDescType:'add' },
			       function(msg){
			    	   document.getElementById("descTitle").value="";
				    	CKEDITOR.instances.serviceContent.setData("");
				    	hideEdit();
				    	if(msg=="保存描述信息成功"){
				    		 var otr = document.getElementById("serviceDescTable").insertRow(-1);
				    	        var checkTd=document.createElement("td");
				    	        var otd1 = document.createElement("td");
				    	        otd1.innerHTML = title;
				    	        var otd2 = document.createElement("td");
				    	        var otd3 = document.createElement("td");
				    	        otd2.innerHTML = desc;
				    	        otd3.innerHTML = "<input type='button' onclick=delServiceDesc('"+title+"',this) value=删除 class='button' />";
				    	        otr.appendChild(otd1); 
				    	        otr.appendChild(otd2); 
				    	        otr.appendChild(otd3); 
				    	}
				    	jAlert(msg,'消息');
			       } 
			); 
	}else{
		jAlert('请您输入完整的内容', '消息');
	}
}

/*************************************************/


function showSmallImage(id){
	 document.getElementById("bgLayer").width = document.body.scrollWidth; 
	 document.all["bgLayer"].style.display="";
	 document.all["bgLayer"].style.height=document.body.scrollHeight;
	 document.getElementById(id).style.display="";
	 timer=setInterval(move,"100");
}
function hideUpload(){
	clearInterval(timer);
	document.all["bgLayer"].style.display="none";
	document.all["Layer2"].style.display="none";
}
function move(){
	document.all["Layer2"].style.top=document.body.scrollTop+(document.body.clientHeight-300)/2;
	document.all["Layer2"].style.left=document.body.scrollLeft+document.body.clientWidth/2-230;
}


function displaySmallImage(event){
   document.getElementById(event).style.display = "none";
   hideUpload();
}

function uploadSmall(){
	document.getElementById("Layer2").style.display = "";
	var top = (document.body.clientHeight-300)/2+"px";
	var left = (document.body.clientWidth-460)/2+"px";
	var div = document.getElementById("Layer2");
	div.style.top = top;
	div.style.left = left;
	showSmallImage("Layer2");
	
	$("#smallImageUpload").click(function(){
		if($("#smallImage1").val()==""){
			jAlert("请选择图片",'消息');
			return ;
		}
		$.ajaxFileUpload   
	    (   
	        {   
	            url:document.getElementById("contextPath").value+'/admin/saveSmallImage',    
	            secureuri:false,   
	            fileElementId:'smallImage1',   
	            dataType: '',   
	            success: function(data, status)   
	            {      
	               jAlert("保存文件成功",'消息');
	               displaySmallImage("Layer2");
	            },   
	            error: function (data, status, e)   
	            {   
	            	jAlert("保存文件失败",'消息');
	                displaySmallImage("Layer2");
	            }   
	        }   
	    )  

	 });
}
/*****************************************************************/
function showLogoImage(id){
	 document.getElementById("bgLayer").width = document.body.scrollWidth; 
	 document.all["bgLayer"].style.display="";
	 document.all["bgLayer"].style.height=document.body.scrollHeight;
	 document.getElementById(id).style.display="";
	 timer=setInterval(moveLogo,"100");
}
function hideLogoUpload(){
	clearInterval(timer);
	document.all["bgLayer"].style.display="none";
	document.all["Layer3"].style.display="none";
}
function moveLogo(){
	document.all["Layer3"].style.top=document.body.scrollTop+(document.body.clientHeight-300)/2;
	document.all["Layer3"].style.left=document.body.scrollLeft+document.body.clientWidth/2-230;
}
function displayLogoImage(event){
  document.getElementById(event).style.display = "none";
  hideLogoUpload();
}
function uploadLogo(){
	
	document.getElementById("Layer3").style.display = "";
	var top = (document.body.clientHeight-300)/2+"px";
	var left = (document.body.clientWidth-460)/2+"px";
	var div = document.getElementById("Layer3");
	div.style.top = top;
	div.style.left = left;
	showSmallImage("Layer3");
	$("#logoImageUpload").click(function(){
		if($("#logoImage1").val()==""){
			jAlert("请选择图片",'消息');
			return ;
		}
		
		$.ajaxFileUpload   
	    (   
	        {   
	            url:document.getElementById("contextPath").value+'/admin/saveLogoImage',    
	            secureuri:false,   
	            fileElementId:'logoImage1',   
	            dataType: '',   
	            success: function(data, status)   
	            {      
	               jAlert("保存文件成功",'消息');
	               displaySmallImage("Layer3");
	            },   
	            error: function (data, status, e)   
	            {   
	            	jAlert("保存文件失败",'消息'); 
	                displaySmallImage("Layer3");
	            }   
	        }   
	    )  

	 });
}

/*****************************************************************/
function showFlash(id){
	 document.getElementById("bgLayer").width = document.body.scrollWidth; 
	 document.all["bgLayer"].style.display="";
	 document.all["bgLayer"].style.height=document.body.scrollHeight;
	 document.getElementById(id).style.display="";
	 timer=setInterval(moveFlash,"100");
}
function hideFlashUpload(){
	clearInterval(timer);
	document.all["bgLayer"].style.display="none";
	document.all["Layer4"].style.display="none";
}
function moveFlash(){
	document.all["Layer4"].style.top=document.body.scrollTop+(document.body.clientHeight-300)/2;
	document.all["Layer4"].style.left=document.body.scrollLeft+document.body.clientWidth/2-230;
}
function displayFlash(event){
 document.getElementById(event).style.display = "none";
 hideFlashUpload();
}
function uploadFlash(){
	document.getElementById("Layer4").style.display = "";
	var top = (document.body.clientHeight-300)/2+"px";
	var left = (document.body.clientWidth-460)/2+"px";
	var div = document.getElementById("Layer4");
	div.style.top = top;
	div.style.left = left;
	showSmallImage("Layer4");
	
	
	
	$("#flashUpload").click(function(){
		if($("#flash1").val()==""){
			jAlert("请选择图片",'消息');
			return ;
		}
		$.ajaxFileUpload   
	    (   
	        {   
	            url:document.getElementById("contextPath").value+'/admin/saveFlash',    
	            secureuri:false,   
	            fileElementId:'flash1',   
	            dataType: '',   
	            success: function(data, status)   
	            {      
	        	jAlert("保存文件成功",'消息');
	               displaySmallImage("Layer4");
	            },   
	            error: function (data, status, e)   
	            {   
	            	jAlert("保存文件失败",'消息');
	                displaySmallImage("Layer4");
	            }   
	        }   
	    );  

	 });
}

/*&*****************************************/
function subPro(){
	var productFee = $("#productFee").val();
	var productDesc = $("#productDesc").val();
	var productName = $("#productName").val();
	var productId = $("#productId").val();
	
	var s = document.getElementById("serviceCodeType");
	var index  = s.selectedIndex;
	var serviceCodeType = $("#serviceCodeType").val();
	var serviceCodeTypeText = "" ;  
	if(serviceCodeType=="P"){
		serviceCodeTypeText = "产品类型";
	}else{
		serviceCodeTypeText = "套餐类型";
	}
	   
	if(productId==""){
		jAlert("请输入类别的代码",'消息');
		return;
	}else{
		if(isNaN(productId)){
			jAlert("请输入数字类型的类别代码",'消息');
			return;
		}
	}
	
	if(productName==""){
		jAlert("请输入类别的名称",'消息');
		return;
	}
	
	if(productDesc==""){
		jAlert("请输入类别的摘要信息",'消息');
		return;
	}
	
	if(productFee==""){
		jAlert("请输入类别的费用",'消息');
		return;
	}else{
		if(isNaN(productFee)){
			jAlert("请输入数字类型的费用",'消息');
			return;
		}
	}
	
	if(serviceCodeType==""){
		jAlert("请选择类别的产品类型",'消息');
		return;
	}
	
	$.ajax({
	    url: document.getElementById("contextPath").value+'/admin/saveProduct',
	    type: 'POST',
	    data: "productId="+productId+"&value="+productFee+"&productName="+productName+"&productSummary="+productDesc+"&productType="+serviceCodeType,
	    timeout: 5000,
	    error: function(){
	    	jAlert('保存数据失败','消息');
	    },
	    success: function(msg){
	    	if(msg=="增加产品类别成功"){
    	        var otr = document.getElementById("productTable").insertRow(-1);
    	        var checkTd=document.createElement("td");
    	        var otd1 = document.createElement("td");
    	        otd1.innerHTML = productId;
    	        var otd2 = document.createElement("td");
    	        var otd3 = document.createElement("td");
    	        otd2.innerHTML = productName;
    	        otd3.innerHTML = "<input type='button' onclick=delProduct('"+productId+"',this) value=删除 class='button' />";
    	        
    	        var otd4 = document.createElement("td");
    	        var otd5 = document.createElement("td");
    	        var otd6 = document.createElement("td");
    	        otd4.innerHTML = productDesc;
    	        otd5.innerHTML = productFee+"元/月";
    	        otd6.innerHTML = serviceCodeTypeText;
    	        otr.appendChild(otd1); 
    	        otr.appendChild(otd2); 
    	        otr.appendChild(otd4);
    	        otr.appendChild(otd5);
    	        otr.appendChild(otd6);
    	        otr.appendChild(otd3); 
    	}
	        jAlert(msg,'消息');
	        $("#productFee").val("");
	        $("#productDesc").val("");
	        $("#productName").val("");
	        $("#productId").val("");
	    }
	});
}

function cacelUpload(a){
	document.getElementById(a).style.display = "none";
}

function saveService(){
	if(document.getElementById("productTable").rows.length==1){
		jAlert("请配置增值业务的具体类别",'消息');
		return;
	}
	window.location.href="../success.jsp";
}

function delServiceDesc(title,a){
	jConfirm('你确定删除本条描述信息吗?', '确认对话框', function(r) {
		if(r){
			$.ajax  
		    (   
		        {   
		            url:document.getElementById("contextPath").value+'/admin/delServiceDesc',    
		            type: 'POST',
		            data: "descriptionName="+title+"&deleteServiceSescType=add",
		            timeout:10000,
		            success: function(msg)   
		            {
		        	if(msg == "删除增值业务描述信息成功"){
		        		var tab = document.getElementById("serviceDescTable");
		        		var tr = a.parentNode.parentNode;
		        		tab.deleteRow(tr.rowIndex);
		        	}
		        	jAlert(msg,'消息');
		            },   
		            error: function (msg)   
		            {   
		            	jAlert('删除增值业务描述信息失败','消息');
		            }   
		        }   
		    );  
		}});
}

function delProduct(id,a){
	jConfirm('你确定删除本条产品类别记录吗?', '确认对话框', function(r) {
		if(r){
	$.ajax  
    (   
        {   
            url:document.getElementById("contextPath").value+'/admin/deleteProduct',    
            data: "productId="+id,
            timeout:10000,
            success: function(msg)   
            {
        	if(msg == "删除增值业务产品类别成功"){
        		var tab = document.getElementById("productTable");
        		var tr = a.parentNode.parentNode;
        		tab.deleteRow(tr.rowIndex);
        	}
        	jAlert(msg,'消息');
            },   
            error: function (msg)   
            {   
            	jAlert('删除增值业务产品类别失败','消息');
            }   
        }   
    ); }});
}

function cancelOprationService(){
	document.getElementById("cancelForm").submit();
}

function forwardPage(url){
	
	var tb = document.getElementById("productTable").childNodes;
   	var tr = tb[0].childNodes;
   	var length = tr.length;
   	//alert("增值业务描述信息"+length+"条");
   	if(length<2){
   		jAlert("增值业务产品类别至少要保留一条","消息");
   		return;
   	}else{
   		window.location.href=url;
   	}
}


